package com.bill99.rpc.config.spring.schema;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.bill99.rpc.common.Constants;
import com.bill99.rpc.registry.RegistryBean;

/**
 * @author sheng.zhang
 */
public class RegistryBeanDefinationParser extends
		AbstractRpcBeanDefinationParser {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected Class<?> getBeanClass(Element element) {
		return RegistryBean.class;
	}

	@Override
	protected void doParse(Element element, ParserContext parserContext,
			BeanDefinitionBuilder builder) {
		logger.info("to parse registry configuration");
		String addr = element.getAttribute(Constants.ADDRESS_KEY);
		if (addr != null && addr.trim().length() > 0) {
			builder.addPropertyValue(Constants.ADDRESS_KEY, addr);
		}
		String cacheDir = element.getAttribute(Constants.CACHEDIR_KEY);
		if (cacheDir != null && cacheDir.trim().length() > 0) {
			builder.addPropertyValue(Constants.CACHEDIR_KEY, cacheDir);
		}
	}

}
